package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.product.pojo.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseAttrValueService;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.pojo.BaseAttrInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BaseAttrInfoController {
    @Autowired
    BaseAttrInfoService baseAttrInfoService;
    @Autowired
    BaseAttrValueService baseAttrValueService;

    //http://api.gmall.com/admin/product/attrInfoList/1/0/0

    /**
     * 根据 分类ID查询具体的属性信息
     * @param c1id
     * @param c2id
     * @param c3id
     * @return
     */
    @GetMapping("/attrInfoList/{c1id}/{c2id}/{c3id}")
    public Result getAttrInfoList(@PathVariable Long c1id, @PathVariable Long c2id, @PathVariable Long c3id){
        List<BaseAttrInfo> list = baseAttrInfoService.getAllByCategoryId(c1id,c2id,c3id);
        return Result.ok(list);
    }

    //http://api.gmall.com/admin/product/saveAttrInfo

    /**
     * 添加属性
     * @param baseAttrInfo
     * @return
     */
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        baseAttrInfoService.updateAttr(baseAttrInfo);
        return Result.ok();
    }

    //http://api.gmall.com/admin/product/getAttrValueList/11
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){
        List<BaseAttrValue> lists = baseAttrValueService.getListByAttrId(attrId);
        return Result.ok(lists);
    }
}
